package br.unipar.bancodedados;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class App 
{
    //gatilho do metodo construtor
    public App(){

        try{
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost:3306/java2011";
            String user = "root";
            String senha = "teste";

            Class.forName(driver);
            Connection conn = DriverManager.getConnection(url, user, senha); // faz a conexao
            Statement stmt = conn.createStatement(); //por uma mesma conexao tera varias requisicoes

            String sql = "select id, login, senha from usuario";
            ResultSet result = stmt.executeQuery(sql);

            while (result.next()){
                System.out.println("ID: " + result.getLong("id"));
                System.out.println("Senha: " + result.getString("login"));
                System.out.println("Senha: " + result.getString("senha"));

            }

            stmt.close();
            conn.close();
        } catch(Exception e){
            e.printStackTrace();
        }

    }

    public static void main( String[] args ){
        //metodo construtor
        new App();

    }
}
